home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / tpwplay.zip / MIDIPLAY.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-13  |  4KB  |  165 lines

  1. unit MidiPlay;
  2.  
  3.   MidiPlay                                     
  4.   Programmer: Charlie Calvert                  
  5.   Date: March 1993                             
  6.  
  7.   Copyright (c) June 1993, by Charlie Calvert
  8.   Feel free to use this code as an adjunct to your own programs.
  9.  
  10.   This unit currently has the name and path of a MIDI file
  11.   hard coded into it. Therefore, it will not play if it can't
  12.   find the path and file on your system. Obviously this means
  13.   there are features I still want to add to this unit. The
  14.   file should be installed on all Windows systems, however.
  15. }
  16.  
  17. interface
  18.  
  19. uses
  20.   MidiUnit, MMSystem, ODialogs, OWindows, PlayDlg,
  21.   PlayerId, Strings, WinDos, WinTypes, WinProcs;
  22.  
  23. const
  24.   DevType:PChar = 'Sequencer';
  25.   FileName:PChar = 'c:\windows\canyon.mid';
  26.  
  27.  
  28. type
  29.   PMidiDlg = ^TMidiDlg;
  30.   TMidiDlg = Object(TPlayDialog)
  31.       Location: LongInt;
  32.       CurTime, LenText, DevInfo: PStatic;
  33.       FileBox: PListBox;
  34.       EdCurDir: PEdit;
  35.     constructor Init(AParent: PWindowsObject; AName: PChar);
  36.     destructor Done; virtual;
  37.     procedure SetUpWindow; virtual;
  38.     procedure ReportStatus; virtual;
  39.     procedure GetDirectoryInfo(var Msg: TMessage);
  40.       virtual Wm_First + Wm_FillDir;
  41.     procedure MciNotify(var Msg: TMessage);
  42.       virtual wm_First + mm_MciNotify;
  43.     procedure MidiAbort(var Msg: TMessage);
  44.       virtual id_First + idAbort;
  45.     procedure MidiOpen(var Msg: TMessage);
  46.       virtual id_First + id_MidiOpen;
  47.     procedure MidiPause(var Msg: TMessage);
  48.       virtual id_First + id_MidiPause;
  49.     procedure MidiPlay(var Msg: TMessage);
  50.       virtual id_First + id_MidiPlay;
  51.     procedure WmTimer(var Msg: TMessage);
  52.       virtual wm_First + wm_Timer;
  53.   end;
  54.  
  55. implementation
  56.  
  57. constructor TMidiDlg.Init(AParent: PWindowsObject; AName: PChar);
  58. begin
  59.   inherited Init(AParent, AName);
  60.   CurTime := New(PStatic, InitResource(@Self, id_MidiNumTracks, MinLen));
  61.   LenText := New(PStatic, InitResource(@Self, id_MidiLenInfo, MinLen));
  62.   DevInfo := New(PStatic, InitResource(@Self, id_MidiDevInfo, MinLen));
  63.   FileBox := New(PListBox, InitResource(@Self, id_WaveList));
  64.   EdCurDir := New(PEdit, InitResource(@Self, id_WaveCurDir, MaxLen));
  65. end;
  66.  
  67. destructor TMidiDlg.Done;
  68. begin
  69.   if GetDeviceId <> 0 then CloseMci;
  70.   inherited Done;
  71. end;
  72.  
  73. procedure TMidiDlg.SetUpWindow;
  74. begin
  75.   inherited SetUpWindow;
  76.   Location := 0;
  77.   StrCopy(WildCard, '*.mid');
  78.   GetWindowsDirectory(CurrentDirectory, MaxLen);
  79.   SetCurDir(CurrentDirectory);
  80.   PostMessage(HWindow, Wm_FillDir, 0, 0);
  81. end;
  82.  
  83. procedure TMidiDlg.GetDirectoryInfo(var Msg: TMessage);
  84. var
  85.   S: array[0..15] of Char;
  86. begin
  87.   SetCurDir(CurrentDirectory);
  88.   StrCopy(S, WildCard);
  89.   if FileBox^.GetCount > 0 then FileBox^.ClearList;
  90.   SendMessage(FileBox^.HWindow, LB_DIR, DDL_ARCHIVE, LongInt(@S));
  91.   FileBox^.SetSelIndex(0);
  92.   EdCurDir^.SetText(CurrentDirectory);
  93. end;
  94.  
  95. procedure TMidiDlg.ReportStatus;
  96. begin
  97.   Mode := GetMode;
  98.   GetStatus;
  99. end;
  100.  
  101. procedure TMidiDlg.MciNotify(var Msg: TMessage);
  102. begin
  103.   KillTimer(HWindow, PlayTimer);
  104.   ReportStatus;
  105.   if Mode = Mci_Mode_Stop then CloseMci;
  106. end;
  107.  
  108. procedure TMidiDlg.MidiAbort(var Msg: TMessage);
  109. begin
  110.   StopMCI;
  111.   ReportStatus;
  112. end;
  113.  
  114. procedure TMidiDlg.MidiOpen(var Msg: TMessage);
  115. begin
  116.   OpenMci(HWindow, FileName, DevType);
  117. end;
  118.  
  119. procedure TMidiDlg.MidiPlay(var Msg: TMessage);
  120. var
  121.   Buf,
  122.   S: array[0..MinLen] of Char;
  123.   Result: LongInt;
  124. begin
  125.   Location := 0;
  126.   if Mode <> Mci_Mode_Pause then begin
  127.     if (FileBox^.GetSelString(Buf, MaxLen) < 0) then begin
  128.     MessageBox(HWindow, 'No file selected in listbox', '', mb_Ok);
  129.     exit;
  130.     end;
  131.     StrCopy(S, CurrentDirectory);
  132.     StrCat(S, '\');
  133.     StrCat(S, Buf);
  134.     OpenMci(HWindow, S, DevType);
  135.     ReportStatus;
  136.     if Mode = MidiError then exit;
  137.     CheckForMapper;
  138.     StartTimer;
  139.     SetTimeFormatMS;
  140.     Result := GetLen;
  141.     wvsPrintf(S, '%ld ms', Result);
  142.     LenText^.SetText(S);
  143.     DevInfo^.SetText(GetInfo(S));
  144.   end;
  145.   PlayMci;
  146.   ReportStatus;
  147. end;
  148.  
  149. procedure TMidiDlg.MidiPause(var Msg: TMessage);
  150. begin
  151.   PauseMidi;
  152.   ReportStatus;
  153. end;
  154.  
  155. procedure TMidiDlg.WmTimer(var Msg: TMessage);
  156. var
  157.   S: array[0..50] of Char;
  158. begin
  159.   Location := GetLocation;
  160.   Str(Location, S);
  161.   CurTime^.SetText(S);
  162.   ReportStatus;
  163. end;
  164. end.